package day_2022_12_to_3.year2023;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haomin
 * @date 2023/02/23 21:50
 **/
public class Day2_23_Num1238 {
    class Solution {
        public List<Integer> circularPermutation(int n, int start) {
            int len = (int) (Math.pow(2, n));
            int[] tmp = new int[len];
            int index = -1;
            for (int i = 0; i < len; i++) {
                tmp[i] = i ^ (i / 2);
                if (index == -1 && tmp[i] == start) {
                    index = i;
                }
            }
            List<Integer> lst = new ArrayList<>();
            for (int i = 0; i < len; i++) {
                lst.add(tmp[index]);
                index = (index + 1) % len;
            }
            return lst;
        }
    }
}